package com.yimils.core.sys.service;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yimils.core.common.dto.GetQueryParams;
import com.yimils.core.sys.beanUtils.PartnerSimVoBeanUtils;
import com.yimils.core.sys.entity.PartnerAgentEntity;
import com.yimils.core.sys.entity.UserEntity;
import com.yimils.core.sys.entity.UserRppEntity;
import com.yimils.core.sys.mapper.PartnerAgentMapper;
import com.yimils.core.sys.mapper.UserRppMapper;
import com.yimils.core.sys.vo.AgentDetailVo;
import com.yimils.core.sys.vo.PartnerSimVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;


@Service("partnerAgentService")
public class PartnerAgentServiceImpl extends ServiceImpl<PartnerAgentMapper, PartnerAgentEntity> implements PartnerAgentService {

    @Resource(name = "userService")
    private UserService userService;

    @Autowired
    private PartnerSimVoBeanUtils beanUtils;


    @Override
    public IPage<PartnerSimVo> getPartner(GetQueryParams queryParam) {
        IPage<UserEntity> users = userService.getUserEntities(queryParam);
        return beanUtils.deepClone(users);
    }

    @Override
    public IPage<AgentDetailVo> getDetails(GetQueryParams queryParams) {
        Page<AgentDetailVo> pageParams = new Page<>(queryParams.getPageNo() == null ? 1 : queryParams.getPageNo(),
                queryParams.getPageSize() == null ? 10 : queryParams.getPageSize());

        if (StringUtils.isNotBlank(queryParams.getOrderBy())
                && StringUtils.isNotBlank(queryParams.getOrder())) {
            if (queryParams.getOrder().equalsIgnoreCase("asc")) {
                pageParams.setAsc(queryParams.getOrderBy());
            } else {
                pageParams.setDesc(queryParams.getOrderBy());
            }
        }
        return getBaseMapper().getAgentDetails(pageParams, queryParams.getAgentId());
    }
}
